package com.elean.pms.service.impl;

import com.elean.pms.utils.JedisUtil;
import com.elean.pms.utils.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.io.IOException;

/**
 * @Auther: 周作为
 * @Date: 2020/3/2 16:45
 * @Description:
 */
public class Produter implements Runnable {

    private JedisUtil jedisUtil;

    byte[] redisKey;

    public Produter(JedisUtil jedisUtil, byte[] redisKey) {
        this.jedisUtil = jedisUtil;
        this.redisKey = redisKey;
    }

    @Override
    public void run() {
        while (true) {
            try {
                int i = 0;
                while (i < 10){
                    jedisUtil.lpush(redisKey, ObjectUtil.object2Bytes(i));
                }
                i++;
                Thread.sleep(2000);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}
